<?php
/**
 * @package     LKVSolutions.JCMS
 * @subpackage  mod_checkdomain
 * @
 * @copyright   Copyright (C) 2014 - 2015 Open Source Matters, Inc. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

defined('_JEXEC') or die;



require_once( dirname(__FILE__) . '/helper.php' );

$doc = JFactory::getDocument();

$loadJquery = $params->get('loadJquery', 1);
$format     = $params->get('format', 'json');

// Load jQuery
if ($loadJquery == '1') {
	//$doc->addScript('//code.jquery.com/jquery-latest.min.js');
}

$js = <<<JS
(function ($) {
	$(document).on('click', 'input[type=submit]', function () {
		var value   = $('input[name=data]').val(),
			action  = $(this).attr('class'),
			request = {
					'option' : 'com_ajax',
					'module' : 'checkdomain',
					'cmd'    : action,
					'data'   : value,
					'format' : '{$format}'
				};
					
		$.ajax({
			type   : 'POST',
			data   : request,
			success: function (response) {
				console.log(response);							
				if(response.data){
					$('.status').html(response.data.ReturnText);
				} else {
					$('.status').html("khong du lieu trong db");
				}
			},
			error: function(response) {	
				$('.status').html("error");
	        }
		});
		return false;
	});
})(jQuery)
JS;

$doc->addScriptDeclaration($js);

$checkDomain= new ModCheckDomainHelper;

require JModuleHelper::getLayoutPath('mod_checkdomain', $params->get('layout', 'default'));